Sketch in data structures for multiple URLs in waypoints. Use GDB reader as guinea...
authorrobertl <robertl>
Sat, 10 Mar 2007 23:36:13 +0000 (23:36 +0000)
committerrobertl <robertl>
Sat, 10 Mar 2007 23:36:13 +0000 (23:36 +0000)
defs.h
gdb.c
util.c
waypt.c

diff --git a/defs.h b/defs.h
index 0c8e081a5e51c3118b4abf10d37d19c7a18192d8..3bfb8b31e20a7521e6ec1bb00c8b25ceadefaa35 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2002, 2003, 2004, 2005  Robert Lipe, robertlipe@usa.net
+    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007  Robert Lipe, robertlipe@usa.net
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -276,6 +276,12 @@ typedef struct {
        unsigned int cet_converted:1;           /* strings are converted to UTF8; interesting only for input */
 } wp_flags;
 
+typedef struct url_link {
+       struct url_link *url_next;
+       char *url;
+       char *url_link_text;
+} url_link;
+
 /*
  * This is a waypoint, as stored in the GPSR.   It tries to not 
  * cater to any specific model or protocol.  Anything that needs to
@@ -325,6 +331,13 @@ typedef struct {
         * Few formats support this.
         */
        char *notes;
+
+       /* This is a bit icky.   Multiple waypoint support is an
+        * afterthought and I don't want to change our data structures.
+        * So we have the first in the waypoint itself and subsequent
+        * ones in a linked list.
+        */
+       struct url_link *url_next;
        char *url;
        char *url_link_text;
 
diff --git a/gdb.c b/gdb.c
index e2c23825c9d30ae0ec4cec68265b6e8976142e40..94a4391389091d7f16245671daeade764673d6d5 100644 (file)
--- a/gdb.c
+++ b/gdb.c
@@ -90,8 +90,8 @@
 
 /* %%% local vars %%% */
 
-/* static char gdb_release[] = "$Revision: 1.48 $"; */
-static char gdb_release_date[] = "$Date: 2007/02/20 20:51:15 $";
+/* static char gdb_release[] = "$Revision: 1.49 $"; */
+static char gdb_release_date[] = "$Date: 2007/03/10 23:36:14 $";
 
 static FILE *fin, *fout;
 static char *fin_name, *fout_name;
@@ -514,10 +514,14 @@ gdb_read_wpt(const size_t fileofs, int *wptclass)
            gdb_is_valid((url_ct >= 0), prefix, "Number of urls (since v3)");
            
            while (url_ct > 0) {
+               char v3xurl[GDB_URL_BUFFERLEN];
                url_ct--;
-               gdb_fread_str(xurl, sizeof(xurl));                      /* URL list */
+               gdb_fread_str(v3xurl, sizeof(v3xurl));                  /* URL list */
+               add_url(res, xstrdup(v3xurl), NULL);
+#if 0
                if ((url == NULL) && (xurl[0] != '\0'))
                    url = xstrdup(xurl);                                /* keep only the first valid entry */
+#endif
            }
            if (url != NULL) {
                strncpy(xurl, url, sizeof(xurl));
diff --git a/util.c b/util.c
index 1af7d25e629c4d83ad9b1a0de8cdbab63e228adf..7d32a2eb126e4598eddb7fca4e2be8c656298dd7 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1641,3 +1641,30 @@ char *get_filename(const char *fname)
        
        return (res == NULL) ? (char *) fname : ++res;
 }
+
+void
+add_url(waypoint *wpt, char *link, char *url_link_text)
+{
+       /* Special case first one; it goes right into the waypoint. */
+       if ((wpt->url == NULL)  && (wpt->url_link_text == NULL)) {
+               wpt->url = link;
+               wpt->url_link_text = url_link_text;
+       } else {
+               url_link *tail;
+               url_link *new_link = xcalloc(sizeof(url_link), 1);
+               new_link->url = link;
+               new_link->url_link_text = url_link_text;
+
+               /* Find current end of chain. */
+               for (tail = wpt->url_next;;tail = tail->url_next) {
+                       if (tail == NULL) {
+                               wpt->url_next = new_link;
+                               break;
+                       }
+                       if (tail->url_next == NULL) {
+                               tail->url_next = new_link;
+                               break;
+                       }
+               }
+       }
+}
diff --git a/waypt.c b/waypt.c
index f58179c776684a74ac858b19e363f126f70b2d5d..da9b98fba8109b47b5c5de7df7b3b4233ec6226d 100644 (file)
--- a/waypt.c
+++ b/waypt.c
@@ -1,7 +1,7 @@
 /*
     Perform various operations on waypoints.
 
-    Copyright (C) 2002-2005 Robert Lipe, robertlipe@usa.net
+    Copyright (C) 2002-2007 Robert Lipe, robertlipe@usa.net
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -304,6 +304,22 @@ waypt_free( waypoint *wpt )
        if (wpt->url_link_text) {
                xfree(wpt->url_link_text);
        }
+       if (wpt->url_next) {
+               url_link *url_next;
+               
+               for (url_next = wpt->url_next; url_next; ) {
+       
+                       url_link *tonuke = url_next;
+                       if (tonuke->url) {
+                               xfree(tonuke->url);
+                       }
+                       if (tonuke->url_link_text) {
+                               xfree(tonuke->url_link_text);
+                       }
+                       url_next = tonuke->url_next;
+                       xfree(tonuke);
+               }
+       }
        if (wpt->icon_descr && wpt->wpt_flags.icon_descr_is_dynamic) {
                xfree((char *)(void *)wpt->icon_descr);
        }